package com.highcom.controller;

import com.highcom.domain.User;
import com.highcom.exception.BusinessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {


    @RequestMapping("/save")
    @ResponseBody//接收请求体
    public List<User> save(@RequestBody User user){

        //调用业务层出翔异常 service
        //System.out.println(1/0);
        String str = null;
        System.out.println(str.length());

        //对用户的非法操纵进行判定，并包装成异常对象进行处理，便于统一管理；
//        if(user.getName().trim().length() < 8){
//            throw new BusinessException("对不起，用户名不满足长度");
//        }
//        if(user.getAge() < 0){
//            throw new BusinessException("对不起，年龄必须是0-100之间的数字!");
//        }


        System.out.println(user);
        ArrayList<User> a1 = new ArrayList<>();
        a1.add(user);
        return a1;
    }
}
